version: "3"

services:
{% if 'redis_nodes' in group_names %}
  redis:
    image: "bitnami/redis:latest"
    container_name: redis
    restart: always
    network_mode: host
    environment:
      REDIS_REPLICATION_MODE: "{{ current_replica_mode | default(redis_replica_mode) }}"
      REDIS_PASSWORD: "{{ redis_password }}"
      REDIS_MASTER_SET: "{{ redis_set }}"
      REDIS_PORT_NUMBER: "{{ redis_port }}"
      REDIS_REPLICA_IP: "{{ global_bond_ip }}"
      REDIS_REPLICA_PORT: "{{ redis_port }}"
      REDIS_DISABLE_COMMANDS: "FLUSHDB,FLUSHALL"
      REDIS_IO_THREADS_DO_READS: "{{ redis_io_thread_do_reads | lower }}"
      REDIS_IO_THREADS: "{{ redis_io_thread }}"
      REDIS_SENTINEL_ANNOUNCE_IP: "{{ global_bond_ip }}"
      REDIS_SENTINEL_ANNOUNCE_PORT: "{{ redis_port }}"
      REDIS_MASTER_HOST: "{{ current_master | default(redis_master) }}"
      REDIS_MASTER_PORT_NUMBER: "{{ redis_port }}"
      REDIS_MASTER_PASSWORD: "{{ redis_password }}"
      REDIS_AOF_ENABLED: "{{ redis_aof_enabled }}"
    volumes:
      - "/usr/share/zoneinfo/{{ global_timezone }}:/etc/localtime"
      - "{{ redis_persistence_path }}:/bitnami/redis/data"
{% endif %}

{% if 'redis_sentinel' in group_names %}
  redis-sentinel:
    image: "bitnami/redis-sentinel:latest"
    container_name: redis-sentinel
    restart: always
    network_mode: host
    environment:
      REDIS_MASTER_SET: "{{ redis_set }}"
      REDIS_MASTER_HOST: "{{ current_master | default(redis_master) }}"
      REDIS_MASTER_PASSWORD: "{{ redis_password }}"
      REDIS_MASTER_PORT_NUMBER: "{{ redis_port }}"
      REDIS_SENTINEL_PORT_NUMBER: "{{ sentinel_port }}"
      REDIS_SENTINEL_ANNOUNCE_IP: "{{ sentinel_announce_ip }}"
      REDIS_SENTINEL_ANNOUNCE_PORT: "{{ sentinel_port }}"
      REDIS_SENTINEL_DOWN_AFTER_MILLISECONDS: "{{ sentinel_down_after_milliseconds }}"
      REDIS_SENTINEL_FAILOVER_TIMEOUT: "{{ sentinel_failover_timeout }}"
    volumes:
      - "/usr/share/zoneinfo/{{ global_timezone }}:/etc/localtime"
      - "{{ redis_persistence_path }}:/bitnami/redis/data"
{% endif %}
